<template>
  <div class="page_box">
    <!-- 搜索区域 开始 -->
    <el-card shadow="never">
      <el-form :inline="true" size="small" :model="formInline" class="demo-form-inline">
        <el-form-item label="名称：">
          <el-input v-model="formInline.term" placeholder="用户名/账号/手机号"></el-input>
        </el-form-item>
        <el-form-item label="注册时间：">
          <el-date-picker v-model="createTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="系统：">
          <el-select v-model="formInline.region" placeholder="活动区域">
            <el-option label="苹果" value="shanghai"></el-option>
            <el-option label="安卓" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="版本：">
          <el-select v-model="formInline.region" placeholder="活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道：">
          <el-select v-model="formInline.region" placeholder="活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地区：">
          <el-select v-model="formInline.region" placeholder="活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="getList">查询</el-button>
        </el-form-item>
        <el-form-item>
          <!-- <el-button size="small" type="success" plain>导出excel</el-button> -->
          <el-button size="small" type="success" plain :loading="exportLoading" @click="downExcel">导出excel</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 搜索区域 end -->

    <!-- 统计数据 开始 -->
    <div class="total_box">
      <span class="sp1">会员总消费<i>{{ staticInfo.consumeAmount }}</i>元</span>
      <span class="sp2">会员总数<i>{{ staticInfo.allTotalCnt }}</i>位</span>
      <span class="sp3">今日新增<i>{{ staticInfo.todayIncreaseCnt }}</i>位</span>
      <span class="sp4">统计日内未过期会员数<i>{{ staticInfo.statValidCnt }}</i>位</span>
      <span class="sp5">统计日内已过期会员数<i>{{ staticInfo.statExpireCnt }}</i>位</span>
    </div>
    <!-- 统计数据 结束 -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <el-table class="tab" size="small" :data="tableData" border stripe>
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="unionId" label="会员ID" show-overflow-tooltip />
        <el-table-column prop="username" label="会员昵称" show-overflow-tooltip />
        <el-table-column prop="age" label="年龄(岁)" show-overflow-tooltip />
        <el-table-column prop="gender" label="性别" show-overflow-tooltip>
          <template slot-scope="scope">{{
            scope.row.gender == 0 ? "男" : "女"
          }}</template>
        </el-table-column>
        <el-table-column prop="city" label="城市" show-overflow-tooltip />
        <el-table-column prop="vipEffectiveDate" label="购买时间" show-overflow-tooltip />
        <el-table-column prop="vipExpirationDate" label="到期时间" show-overflow-tooltip />
        <el-table-column prop="vipDays" label="购买时间" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.vipDays }}天</template>
        </el-table-column>
        <el-table-column prop="vipStatus" label="状态" show-overflow-tooltip>
          <template slot-scope="scope">{{
            scope.row.vipStatus == 2 ? "已过期" : scope.row.vipDays + "天"
          }}</template>
        </el-table-column>
        <el-table-column prop="consumeCnt" label="消费次数" show-overflow-tooltip />
        <el-table-column prop="consumeAmount" label="消费总额" show-overflow-tooltip>
          <template slot-scope="scope">{{scope.row.consumeAmount||0}}元</template>
        </el-table-column>
        <el-table-column prop="address" label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="lookDetail(scope.row)">详情</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->

    <!-- 弹框 开始 -->
    <glsx-dialog :show="showDialog" title="会员详细信息" width="50%" @close="closeDialog">
      <div class="">
        <div class="tips_box">
          <span>会员消费记录</span>
          <span>开通会员：{{ vipHistory.length }}次</span>
        </div>
        <table class="tab tab_line">
          <thead>
            <tr>
              <th width="10%">序号</th>
              <th width="24%">购买会员时间</th>
              <th width="22%">等级</th>
              <th width="22%">截止时间</th>
              <th width="22%">消费金额</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in vipHistory" :key="index">
              <td>{{ index + 1 }}</td>
              <td>{{ item.createdDate }}</td>
              <td>{{ item.createdDate }}</td>
              <td>{{ item.vipExpirationDate }}</td>
              <td>{{ item.actualCost }}元</td>
            </tr>
            <tr v-if="!vipHistory || vipHistory.length <= 0">
              <td>暂无数据</td>
            </tr>
          </tbody>
        </table>
        <div class="tips_box">
          <span>邀请好友列表</span>
          <span>邀请好友：{{ inviteUsers.length }}次</span>
        </div>
        <table class="tab tab_line">
          <thead>
            <tr>
              <th width="10%">序号</th>
              <th width="24%">好友ID</th>
              <th width="22%">注册时间</th>
              <th width="22%">是否有邀请</th>
              <th width="22%">好友启动次数</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in inviteUsers" :key="index">
              <td>{{ index + 1 }}</td>
              <td>{{ item.unionId }}</td>
              <td>{{ item.registerDate }}</td>
              <td>{{ item.inviteCnt }}</td>
              <td>{{ item.launchCnt }}</td>
            </tr>
            <tr v-if="!inviteUsers || inviteUsers.length <= 0">
              <td colspan="5" align="center">暂无数据</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div slot="footer">
        <el-button type="success" plain size="small" @click="closeDialog">关闭</el-button>
      </div>
    </glsx-dialog>
    <!-- 弹框 end -->
  </div>
</template>

<script>
import {
  GETCUSTUSERVIPSEARCH,
  GETVIPINFO,
  GETCUSTUSERVIPSTATISTIC,
  VIPLISTEXPORT,
} from "@/http/interface";
import { showModal, showToast } from "@/common/util";
import { exportExcel } from "@/common/common";
import GlsxDialog from "@/components/Dialog";
export default {
  components: {
    GlsxDialog,
  },
  data() {
    return {
      formInline: {},
      createTime: [],
      tableData: [],
      pageSize: 10,
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 30, 40],
      showDialog: false,
      vipHistory: [],
      inviteUsers:[],
      staticInfo: {},
      exportLoading: false,
    };
  },
  mounted() {
    this.getList();
    this.getStatic();
  },
  methods: {
    /** 获取参数 */
    getParams() {
      let _this = this;
      let o = JSON.parse(JSON.stringify(_this.formInline)) || {};
      let n = _this.createTime;
      console.log(n);
      if (n && n.length > 0) {
        o.sDate = n[0];
        o.eDate = n[1];
      } else {
        delete o.sDate;
        delete o.eDate;
      }
      o.pageNumber = this.pageNumber;
      o.pageSize = this.pageSize;
      return o;
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GETCUSTUSERVIPSEARCH(oParams).then((res) => {
        console.log(res);
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    /** 查看详情 */
    lookDetail(row) {
      this.showDialog = true;
      let oParams = {};
      let _this = this;
      oParams.userId = row.userId;
      GETVIPINFO(oParams).then((res) => {
        let obj = res.data || {};
        _this.vipHistory = obj.vipHistory || [];
        _this.inviteUsers = obj.inviteUsers || []
      });
    },

    /** 关闭弹框 */
    closeDialog() {
      this.showDialog = false;
      this.certification = {};
      this.photoList = [];
      this.profile = {};
      this.vipInfo = {};
    },

    // 获取统计数据
    getStatic() {
      let _this = this;
      GETCUSTUSERVIPSTATISTIC().then((res) => {
        _this.staticInfo = res.data || {};
      });
    },

    /** 导出excel */
    downExcel() {
      let _this = this;
      let options = {};
      let _obj = _this.getParams();
      let url = VIPLISTEXPORT;
      delete _obj.pageNumber;
      delete _obj.pageSize;
      _this.exportLoading = true;
      options.url = url;
      options.data = _obj;
      options.fileName = "充值会员列表.xlsx";
      options.method = "GET";
      options.success = function () {
        _this.exportLoading = false;
      };
      options.fail = function () {
        _this.exportLoading = false;
      };
      exportExcel(options);
    },
  },
};
</script>

<style lang="scss" scoped>
.link_group {
  margin-top: 10px;
  text-align: right;
}
.avatar {
  height: 30px;
}
.row_box {
  display: flex;
  .cell_box {
    flex: 1;
    display: flex;
    padding: 8px 0;
    .name {
      width: 80px;
      text-align: right;
      font-size: 14px;
    }
  }
}
.total_box {
  margin: 10px 0 0 0;
  // background:#f0f9eb;
  padding: 10px;
  font-size: 14px;
  span {
    position: relative;
    margin: 0 30px 0 0;
    padding-left: 12px;
    color: #666;
    i {
      font-size: 24px;
      font-style: normal;
      margin: 0 5px;
    }
  }
  span:after {
    display: block;
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 100%;
    background: #f00;
    top: 50%;
    left: 0px;
    margin-top: -4px;
  }
  .sp1:after {
    background: #49a9ee;
  }
  .sp2:after {
    background: #7dc856;
  }
  .sp3:after {
    background: #ffd86e;
  }
  .sp4:after {
    background: #cc33ff;
  }
  .sp5:after {
    background: #ff9933;
  }
}
.tab_line {
  width: 100%;
  border: 1px solid #d8d8d8;
  border-collapse: collapse;
  thead {
    th {
      border: 1px solid #d8d8d8;
      padding: 8px;
      text-align: left;
    }
  }
  td {
    border: 1px solid #d8d8d8;
    padding: 8px;
  }
}
.tips_box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
}
</style>
